﻿using System;
using WiMo.Games;
using WiMo.Games.Inputs;
using WiMo.Games.Audio;

namespace Audio
{
    /// <summary>
    /// Main Game Class.
    /// 
    /// An interface is used so we can swap out all the implementations for the
    /// different components of the engine.
    /// </summary>
    public class Game : IGame
    {
        public IGameAudio _audio;

        public IGameEngine Engine { get; set; }

        public Game(IGameEngine engine)
        {
            Engine = engine;
            Engine.ContentManager.ContentLocation = "Content";
        }

        public void Initialize()
        {
            Engine.Display.BackgroundColor = Color.CornFlowerBlue;

            Engine.InputManager.MenuBarBackgroundColor = Color.Black;
            Engine.InputManager.SoftMenuFontColor = Color.White;
            Engine.InputManager.RightSoftButton = "Exit";
            Engine.InputManager.LeftSoftButton = "Play Audio";
        }

        public void BeginRun(){}
        public void CreateMenus(){ }

        public void LoadContent()
        {
            _audio = Engine.ContentManager.LoadAudio("blip");
        }

        IInputManager _previous;
        public void Update(GameTime gameTime)
        {

            if (Engine.InputManager.WasPressed(_previous, Keys.LeftSoftButton))
                _audio.Play();

            if (Engine.InputManager.WasPressed(_previous, Keys.RightSoftButton))
                Engine.Exit();

            _previous = Engine.InputManager.GetKeysState();
        }

        public void Draw(GameTime gameTime)
        {
            Engine.Display.DrawText(new PointF(Engine.Display.TargetSize.Width / 2, 50.0f), "Hello WiMo", Engine.DefaultFont, Color.Yellow, WiMo.Games.Drawables.Origin.Center);
        }

        public bool CanExit()
        {
            return true;
        }
    }
}
